(function () {
    var EVENT_CLICK = Laya.Event.CLICK;
    var io = ppt.io;

    function shopList() {
        shopList.super(this);
        this.Data = null;
        this._index = null;
        this.curSelectedIndex = null;
        this.init();
    }
    Laya.class(shopList, "Com.Shop.List", ui.Shop.ShopListUI);
    var _proto = shopList.prototype;

    _proto.init = function () {
       // io.register("game::enter", this, this.maxbox);
        this.shopsList.height = Laya.stage.height;
        this.shopsList.top = 200;
        this.shopsList.bottom = 50;

        this.shopsList.mouseHandler = new laya.utils.Handler(this, this.onSelect);
    }
    //商品信息
    _proto.upData = function (data, index) {
        this.curSelectedIndex = index;
        this.shopsList.array = [];
        this.Data = data.shopInfo;
        this.shopsList.renderHandler = new laya.utils.Handler(this, this.listshop);
        if (data.code == 0) {
            var data = data.shopInfo;
            var itemId;
            this._itemId = [];
            this._num = [];
            this._name = [];
            this._price = [];
            this._desc = [];
            this._type = [];
            for (var i = 0; i < data.length; i++) {
                data[i].title = data[i].name;
                data[i].shopNum = data[i].num;
                data[i].money = data[i].price + '/个';
                data[i].trend = (data[i].currency) - 1;

            }
            this.shopsList.array = data;
        } else {
            console.log(data.msg);
        }
    }
    _proto.listshop = function (shop, index) {
        shop.getChildByName('picall').skin = 'res/props/' + this.Data[index].item_id + '.png';
    }

    //选择购买商品
    _proto.onSelect = function (e, index) {
        if (e.type == Laya.Event.CLICK) {
            var selectedIndex = this.curSelectedIndex;

            this._index = index;
            if (this.Data[this._index].num == 0) {
                var config = {
                    msg : "当前时段该商品已售完，请选择其他商品",
                    btn : {
                        btnCancel : false,
                        btnConfirm : {
                            skin : "confirm"
                        }
                    }
                }
                ppt.director.popScene(new Alert.Public(config));
                return;
            }
            var data = this.Data[this._index];
                data.purchaseNum = 1;
            ppt.director.popScene(new Alert.Purchase(data));
        }
    }
})();